﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Core.Infrastructure.EventArgs;
using Microsoft.Practices.Composite.Regions;
using Core.Infrastructure.Constants;

namespace Core.Infrastructure.ScreenManager
{
    public class RegionViewInjector : IViewInjector
    {
        private IRegionManager regionManager;

        public RegionViewInjector(IRegionManager regionManager)
        {
            this.regionManager = regionManager;
        }

        private IRegion MainRegion
        {
            get
            {
                return this.regionManager.Regions[RegionConstants.RegionMainArea];
            }
        }

        public void RemoveAndDeactivateIfShould(string regionName, Control view)
        {
            if (regionManager.Regions[regionName].Views.Contains(view))
            {
                regionManager.Regions[regionName].Deactivate(view);
                regionManager.Regions[regionName].Remove(view);
            }
        }

        public void InjectView(string regionName, Control view)
        {
            var region = this.regionManager.Regions[regionName];

            region.Add(view);
            region.Activate(view);
        }
    }
}
